package com.ruoyi.admin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.admin.domain.Prescript;
import com.ruoyi.admin.service.IPrescriptService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * prescriptController
 * 
 * @author ruoyi
 * @date 2023-01-11
 */
@RestController
@RequestMapping("/drugs/prescript")
public class PrescriptController extends BaseController
{
    @Autowired
    private IPrescriptService prescriptService;

    /**
     * 查询prescript列表
     */
    @PreAuthorize("@ss.hasPermi('drugs:prescript:list')")
    @GetMapping("/list")
    public TableDataInfo list(Prescript prescript)
    {
        startPage();
        List<Prescript> list = prescriptService.selectPrescriptList(prescript);
        return getDataTable(list);
    }

    /**
     * 导出prescript列表
     */
    @PreAuthorize("@ss.hasPermi('drugs:prescript:export')")
    @Log(title = "prescript", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Prescript prescript)
    {
        List<Prescript> list = prescriptService.selectPrescriptList(prescript);
        ExcelUtil<Prescript> util = new ExcelUtil<Prescript>(Prescript.class);
        util.exportExcel(response, list, "prescript数据");
    }

    /**
     * 获取prescript详细信息
     */
    @PreAuthorize("@ss.hasPermi('drugs:prescript:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(prescriptService.selectPrescriptById(id));
    }

    /**
     * 新增prescript
     */
    @PreAuthorize("@ss.hasPermi('drugs:prescript:add')")
    @Log(title = "prescript", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Prescript prescript)
    {
        return toAjax(prescriptService.insertPrescript(prescript));
    }

    /**
     * 修改prescript
     */
    @PreAuthorize("@ss.hasPermi('drugs:prescript:edit')")
    @Log(title = "prescript", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Prescript prescript)
    {
        return toAjax(prescriptService.updatePrescript(prescript));
    }

    /**
     * 删除prescript
     */
    @PreAuthorize("@ss.hasPermi('drugs:prescript:remove')")
    @Log(title = "prescript", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(prescriptService.deletePrescriptByIds(ids));
    }
}
